package dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;

import model.Computador;
import model.Manutencao;

public class ManutencaoDAO extends PersistenciaDAO {

	
	
	public Collection<HashMap<String, Object>> buscarDadosManutencaoBrowse() throws SQLException {

		Collection<HashMap<String, Object>> result = new ArrayList<HashMap<String,Object>>();
		Statement sta = connection.createStatement();
		ResultSet elements = sta.executeQuery(
				" SELECT m.cd_manutencao as codigo, "+
				"  		m.ds_defeito as descricao "+
				" FROM quiosque.manutencao m "+
				" ORDER BY m.cd_manutencao ");
		
		while (elements.next()) {
			HashMap<String, Object> map = new HashMap<String, Object>();
			map.put("codigo", elements.getInt("codigo"));
			map.put("descricao", elements.getString("descricao"));
			result.add(map);
		}
		return result;
	}
	
	public Manutencao buscarManutencaoPorId(int id) throws SQLException {
		Manutencao result = null;
		Statement sta = connection.createStatement();
		ResultSet elements = sta
				.executeQuery("SELECT * FROM manutencao WHERE cd_manutencao = "	+ id);

		while (elements.next()) {
			result = new Manutencao();
			Computador computador = new ComputadorDAO()
					.buscarComputadorPorId(elements.getInt("cd_computador"));
			result.setId(elements.getInt("cd_manutencao"));
			result.setComputador(computador);
			result.setData(elements.getString("dt_manutencao"));
			result.setDescricaoDefeito(elements.getString("ds_defeito"));
			result.setDescricaoSolucao(elements.getString("ds_solucao"));
			result.setCusto(elements.getDouble("vl_custo"));
		}
		return result;
	}
}